<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"  />
	<title>canvas绘图练习</title>
</head>
<body>
	<canvas id="drawing" width="900" height="900"></canvas>
	<script type="text/javascript" src="../Code/event.js"></script>
	<script type="text/javascript">
		var drawing = document.getElementById("drawing");
		if (drawing.getContext) {
			var context = drawing.getContext("2d");
			context.strokStyle = "red";
		//绘制矩形
			context.fillStyle = "#ff0000";
			context.fillRect(10,10,50,50)
		//绘制半透明蓝色矩形
			context.fillStyle = "rgba(0,0,255,0.5)";
			context.fillRect(30,30,50,50);
		//清除一小部分矩形
			context.clearRect(40,40,10,10);

		//绘制一个不带数字的时钟表盘
			//开始路径
			context.beginPath();
			//绘制外圆
			context.arc(200,200,99,0,2*Math.PI,false);
			//绘制内圆
			context.moveTo(294,200);
			context.arc(200,200,94,0,2*Math.PI,false);
			//绘制分针
			context.moveTo(200,200);
			context.lineTo(200,125);
			//绘制时针
			context.moveTo(200,200);
			context.lineTo(135,200);
			context.stroke();

			//绘制文本
			context.font = "bold 14px Arial";
			context.textAlign = "center";
			context.textBaseLine = "middle";
			context.fillText("12",200,120);
			context.fillText("6",200,290);
			context.fillText("3",285,205);
			context.fillText("9",115,205);
		//将原点变换为表盘中心
			context.beginPath();
			context.arc(500,500,100,0,2*Math.PI,false);
			context.moveTo(595,500);
			context.arc(500,500,95,0,2*Math.PI,false);
			//变换原点
			context.translate(500,500);
			context.rotate(1);
			context.moveTo(0,0);
			context.lineTo(0,-85);
			context.moveTo(0,0);
			context.lineTo(-65,0);
			context.stroke();
		//绘制渐变矩形
		context.translate(100,100)
		var gradient = context.createLinearGradient(30,30,50,50);
		gradient.addColorStop(0,"white");
		gradient.addColorStop(1,"black");
		context.fillStyle = gradient;
		context.fillRect(30,30,50,50);

		};
	</script>

</body>
</html>